package cn.yunhe.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.yunhe.biz.IMajorsBiz;
import cn.yunhe.biz.IProvienceMessageBiz;
import cn.yunhe.biz.IProviencesBiz;
import cn.yunhe.biz.IScoreBiz;
import cn.yunhe.biz.IUniverstityBiz;
import cn.yunhe.biz.IUserBiz;
import cn.yunhe.biz.MajorsBizImpl;
import cn.yunhe.biz.ProvienceBizImpl;
import cn.yunhe.biz.ProvienceMessageBizImpl;
import cn.yunhe.biz.ScoreBizImpl;
import cn.yunhe.biz.UniverstityBizImpl;
import cn.yunhe.biz.UserBizImpl;
import cn.yunhe.entity.Enroll_in_province;
import cn.yunhe.entity.Majors;
import cn.yunhe.entity.ProvienceMessage;
import cn.yunhe.entity.Proviences;
import cn.yunhe.entity.University;
import cn.yunhe.entity.User;

/**
 * Servlet implementation class DoBackstage
 */
public class DoBackstage extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DoBackstage() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
		HttpSession session = request.getSession();
		PrintWriter out =response.getWriter();
		IProviencesBiz ipb = new ProvienceBizImpl();
		List<Proviences> plist = ipb.searchProviences();
		session.setAttribute("plist", plist);
		
		String opt = request.getParameter("opt");
		if("getUniversity".equals(opt)){
			IUniverstityBiz iub = new UniverstityBizImpl();
			List<University> universtitylist = iub.getAll();
			session.setAttribute("universtitylist", universtitylist);
			response.sendRedirect("./backstage/university.jsp");
		}else if("getMajors".equals(opt)){
			IMajorsBiz imb = new MajorsBizImpl();
			List<Majors> majorsList = imb.getAllMajorsByRate();
			session.setAttribute("majorsList", majorsList);
			response.sendRedirect("./backstage/majors.jsp");
		}else if("getProvinces".equals(opt)){
			IProvienceMessageBiz ipmz = new ProvienceMessageBizImpl();
			List<ProvienceMessage> proList = ipmz.getAllProvince();
			session.setAttribute("proList", proList);
			response.sendRedirect("./backstage/provincemessage.jsp");
		}else if("getScore".equals(opt)){
			
			IProvienceMessageBiz ipmz = new ProvienceMessageBizImpl();
			List<ProvienceMessage> proList = ipmz.getAllProvince();
			session.setAttribute("proList", proList);
			
			IUniverstityBiz iub = new UniverstityBizImpl();
			List<University> universtitylist = iub.getAll();
			session.setAttribute("universtitylist", universtitylist);
			
			IScoreBiz isb = new ScoreBizImpl();
			List<Enroll_in_province> eipList = isb.getAll();
			session.setAttribute("eipList", eipList);
			response.sendRedirect("./backstage/enroll.jsp");
		}else if("getUser".equals(opt)){
			IUserBiz iub = new UserBizImpl();
			List<User> ulist = iub.getAll();
			session.setAttribute("ulist", ulist);
			response.sendRedirect("./backstage/user.jsp");
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
